<?php
declare (strict_types = 1);

namespace app\mall\model;

use app\mall\enum\OpUserEnum;
use app\mall\enum\ScoreEnum;
use app\mall\enum\YesNoEnum;
use app\mall\model\traits\GoodsTrait;
use app\mall\model\traits\OpUserTrait;
use app\mall\model\traits\StoreTrait;
use think\Model;

/**
 * @mixin Model
 * @property ScoreEnum score_enum
 * @property array user
 * @property OpUserEnum user_type_enum
 * @property string user_type_text
 * @property string user_name
 * @property string user_avatar
 * @property integer show
 * @property string show_text
 * @property integer rmd
 * @property string rmd_text
 */
class MallOrderEvaluate extends MallBase
{
    use GoodsTrait;
    use StoreTrait;
    use OpUserTrait;

    public function getScoreTextAttr($key, $data): string
    {
        return $this->score_enum->getZhName();
    }

    public function getScoreEvaluateAttr($key, $data): string
    {
        return $this->score_enum->getEvaluate();
    }

    public function getUserNameAttr()
    {
        return $this->user['name'];
    }

    public function getUserAvatarAttr()
    {
        return $this->user['avatar'];
    }

    public function getScoreEnumAttr($key, $data)
    {
        return new ScoreEnum($data['score']);
    }

    public function setImagesAttr($value, $data)
    {
        return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : '[]';
    }

    public function getImagesAttr($value, $data)
    {
        return $value ? json_decode($value, true) : [];
    }

    public function getUserTypeEnumAttr($key, $data)
    {
        return new OpUserEnum($data['user_type']);
    }

    public function getUserTypeTextAttr($key, $data)
    {
        return $this->user_type_enum->getZhName();
    }

    public function getShowTextAttr()
    {
        return (new YesNoEnum($this->show))->getZhName();
    }

    public function getRmdTextAttr()
    {
        return (new YesNoEnum($this->rmd))->getZhName();
    }
}
